package cn.hsa.fqz.listener;


import cn.hsa.fqz.task.service.TUserMappingService;
import cn.hsa.hsaf.core.framework.util.CurrentUser;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * @author 丁志敏
 * @version v1.0
 * @apiNote 功能描述:()
 * @date create in 2023/4/9 22:47
 */
@Slf4j
@Component
public class UserOperateListener implements ApplicationListener<UserOperateEvent> {

    @Autowired
    private TUserMappingService userMappingService;


    @Override
    public void onApplicationEvent(UserOperateEvent event) {
        CurrentUser currentUser = event.getCurrentUser();
        if(StringUtils.isNotEmpty(currentUser.getUserAcct())){
            boolean b = userMappingService.saveOrUpdateCurrentUser(event.getCurrentUser());
            if(b){
                log.info("用户信息更新成功！，user_info = {}",JSON.toJSONString(event.getCurrentUser()));
            }
        }
    }


}
